@echo off
echo Installing Log Server as Windows Service...
echo.

:: Check if Node.js is installed
node --version >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Node.js is not installed or not in PATH
    echo Please install Node.js first: https://nodejs.org/
    pause
    exit /b 1
)

:: Check if npm is available
npm --version >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: npm is not available
    pause
    exit /b 1
)

:: Install node-windows if not already installed
echo Checking for node-windows dependency...
npm list node-windows >nul 2>&1
if %errorlevel% neq 0 (
    echo Installing node-windows...
    npm install node-windows
    if %errorlevel% neq 0 (
        echo Error: Failed to install node-windows
        pause
        exit /b 1
    )
)

:: Run the service installation script
echo Running service installation...
node install-windows-service.js

if %errorlevel% equ 0 (
    echo.
    echo Service installation completed successfully!
    echo You can now manage the service through Windows Services (services.msc)
    echo Service name: LogServer
) else (
    echo.
    echo Service installation failed!
)

pause